var Redis = require('ioredis');

//数据库地址
const host = "127.0.0.1";

//数据库服务端口
const port = 6379;

//数据库密码
const password = "moyu123";

//数据库培训
const db = 0; 


var redis = new Redis({
    port: port,         // Redis port
    host: host,         // Redis host
    family: 4,          // 4 (IPv4) or 6 (IPv6)
    password: password, 
    db: db
})

redis.on('connect', () =>{
    //模拟ping维持链接活跃，防止2分钟无流量断链，抛出异常
    setInterval(() =>{
        redis.get('ping');
    }, 60000)
})

module.exports = redis;